package com.shareyi.baseproject.kernel.common.event;

import com.shareyi.baseproject.kernel.common.enums.EventSourceEnum;
import com.shareyi.baseproject.kernel.common.retry.RetryBizCodeEnum;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

/**
 * Event 基类
 *
 * @author qiulong
 * @date 2020-03-16
 */
@Getter
@Setter
@ToString
public abstract class Event {

    /**
     * 消息ID
     */
    private String id;
    /**
     * 事件戳
     */
    private Long timestamp;
    /**
     * 事件来源
     */
    private EventSourceEnum eventSource;

    /**
     * 获取消息重试消息体中的业务类型
     *
     * @return
     */
    public abstract RetryBizCodeEnum getRetryBizCode();

    public void init() {
        if (timestamp == null) {
            timestamp = System.currentTimeMillis();
        }
    }

    /**
     * 获取事件的业务主键
     *
     * @return
     */
    public abstract String getBizKey();

}
